<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>随机生成指定长度的字符串</title>
	</head>
	<body>
	</body>
	<script>
		//所需要的字符串
		function getLetters(){
			var str = '';
			for(var i = 0;i<26;i++){
				str += String.fromCharCode(97+i);
				str += String.fromCharCode(66+i);
			}
			
			return str;
		}
		//生成指定长度的字符串
		function getRandomStr(n){
			var str = getLetters();
			var temp = '';
			for(var i =0;i<n;i++){
				temp += str.charAt(Math.floor(Math.random()*str.length));
			}
			return temp;
		}
		alert(getRandomStr(5));
	</script>
</html>
